import pytest
import os

os.chdir("..")

class TestCollector:
    def __init__(self):
        self.test_count = 0

    def pytest_collection_modifyitems(self, items):
        self.test_count = len(items)
        print(f"收集到 {self.test_count} 个测试用例")

# 创建收集器实例
collector = TestCollector()

# 执行 pytest 并传入收集器
pytest.main(["-qq", "--collect-only"], plugins=[collector])

# 获取用例数量
test_count = collector.test_count
print(f"总测试用例数: {test_count}")